package com.bz.sea;

import com.facebook.react.ReactActivity;

import android.Manifest;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle; // here
import android.support.v4.content.ContextCompat;

import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen; // here

public class MainActivity extends ReactActivity {
    private static MainActivity mainActivity;
    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "sea";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this, true);  // here
        isPermissionLocal();
        super.onCreate(savedInstanceState);
    }

    public MainActivity() {
            mainActivity = this;
        }

        public static MainActivity getMainActivity() {
            return mainActivity;
        }

        private String[] permissionArray = new String[]{
                    Manifest.permission.WRITE_EXTERNAL_STORAGE};

             public void isPermissionLocal() {
                    // For Android < Android M, self permissions are always granted.

                    try {
                        final PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
                        int targetSdkVersion = info.applicationInfo.targetSdkVersion;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

                            if (targetSdkVersion >= Build.VERSION_CODES.M) {
                                int permissionCheck = ContextCompat.checkSelfPermission(MainActivity.this,
                                        Manifest.permission.ACCESS_COARSE_LOCATION);
                                // 权限未允许
                                if (permissionCheck != 0) {
                                    PermissionUtils.checkPermissionArray(MainActivity.this, permissionArray, 2);
                                } else {
                                    // 申请权限后的操作
            //                        getData();
                                }
                            } else {
                                // targetSdkVersion < Android M, we have to use PermissionChecker
                                // 申请权限后的操作
            //                    getData();
                            }
                        } else {
                            // 申请权限后的操作
            //                getData();
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        e.printStackTrace();
                    }
                }
}
